//*************************************************************************
//	Includes Section
//*************************************************************************
//	OpenCV stuff
#include "cv.h"
#include "cxtypes.h"

//	STL stuff
#include <vector>
using std::vector;


//*************************************************************************
//	Various definitions
//*************************************************************************
#define DEBUG_MODE

typedef enum NotifyActions_enum
{
	NOTIFY_CAR_ENTRY,
	NOTIFY_CAR_LP_NUM,
	NOTIFY_CAR_ENTRY_ERROR
} NotifyActions;

typedef vector<IplImage *> ImageVec;

//-------------------------------------------------------------------------
//	Class:			PlateLocalization
//	Description:	Singleton class. Responsible on finding a licence plate
//					in a given set of pictures, and sending it to an OCR 
//					thread.
//--------------------------------------------------------------------------
class PlateLocalization
{
public:
	static PlateLocalization *Instance();
	void FindLicenseNumber(ImageVec vec);
	void FindLicenseNumber(IplImage *img);

private:
	PlateLocalization(){};
	~PlateLocalization(){};

	//	Used to notify the db of a car entry event
	void NotifyDB(NotifyActions act, long data);

	//	Used by singleton's public function to begin async (via new thread) LPN finding
	void InvokeFinding(IplImage *img);
	
	//	Methods to locate a LP suspect
	bool ExtractYellowFromImg(IplImage *img);
	bool TresholdYellow(IplImage *img);
	bool SegmentLargestObject(IplImage *img);
	int SegmentObject(const IplImage *src, IplImage *mask, int x, int y);
	void FillObject(IplImage *img);

	bool FindSquare(IplImage *img, CvPoint *points);
	bool TrimPicture(IplImage *img, IplImage **trimmed, CvPoint *points);
	bool FindNumber(IplImage *img);	//	this methods calls the OCR module

	bool FindIntersection(CvPoint l0p0, CvPoint l0p1, CvPoint l1p0, CvPoint l1p1, CvPoint *inter);
	bool CheckIntersection(float rho0, float theta0, float rho1, float theta1, int width, int height);
	CvSize BoundingBox(CvPoint *points, CvPoint *pointsOrderedTLBLTRBR);
};